<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var functionName = document.getElementById("functionName");
		var parentId = document.getElementById("parentId");
		var functionSort = document.getElementById("functionSort");
		var url = document.getElementById("url");
		
		var action1 = document.getElementsByName("action1");
		var actionCode = document.getElementById("actionCode");
		var actionName = document.getElementById("actionName");
		
		if(functionName.value == ""){
			alert("功能名称不能为空！");
			return false;
		}
		
		if(parentId.value == -1){
			alert("请选择上级功能！");
			return false;
		}
		
		if(functionSort.value == ""){
			alert("功能排序不能为空！");
			return false;
		}
		
		if(action1[0].checked){
			if(actionCode.value == ""){
				alert("操作编码不能为空！");
				return false;
			}
			if(actionName.value == ""){
				alert("操作名称不能为空！");
				return false;
			}
		}
		return true;
	}

	function back(){
		window.location.href = "./function.do";
		window.location.target = "main";
	}
	
	function addSaleRecord(){
		window.location.href = "addSaleRecord.html";
		window.location.target = "main";
	}
	
	function updateSaleRecord(){
		window.location.href = "updateRecord.html";
		window.location.target = "main";
	}
	
	function showHidden(id){
		var obj = document.getElementById(id);
		var objs = document.getElementsByName("action1");
		if(obj.style.display == "none" && objs[0].checked){
			document.getElementById(id).style.display = "block";
		}else if(objs[1].checked){
			document.getElementById(id).style.display = "none";
		}
	}
	
	function save(){
		if(checkForm()){
			document.addFunctionForm.action = "./function.do?action=addFunction";
			document.addFunctionForm.target = "main";
			document.addFunctionForm.submit();
		}
	}
	
	function initPage(result){
		if(result == 1){
			alert("保存成功！");
		}
	}
-->
</script>
</head>
<body onload="initPage('${result}')">
<form name="addFunctionForm" action="" method="post">		
	<a class="common_title">>> 您现在的位置：基础设置 >> 新增功能</a>
	
	<div class="tools">
		<a class="save" href="javascript:save();" title="保存" hidefocus="true">保存</a>&nbsp;&nbsp;
		<a class="reset" href="#" title="重置" hidefocus="true">重置</a>&nbsp;&nbsp;
		<a class="back" href="javascript:back();" title="返回" hidefocus="true">返回</a>&nbsp;&nbsp;
	</div>

<table class="table" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top">
			<table class="table_input1" cellpadding="0" cellspacing="0" style="padding: 0 0 0 5px;">
				<tr>
					<td class="title3" width="15%">功能名称：</td>
					<td class="title3"><input id="functionName" name="functionName" class="input1" type="text"/></td>
					<td class="title3" width="18%">上级功能：</td>
					<td class="title3">
						<select id="parentId" name="parentId">
							<option value="-1">--------请选择--------</option>
							<option value="0">无</option>
							<c:forEach var="function" items="${functions}">
								<c:if test="${function.parentId == 0}">
								<option value="${function.id}">${function.functionName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td class="title3" width="15%">功能排序：</td>
					<td class="title3" width="">
						<input id="functionSort" name="functionSort" class="input1" type="text"/>
					</td>
					<td class="title3" width="15%">URL：</td>
					<td class="title3" width="">
						<input id="url" name="url" class="input1" type="text"/>
					</td>
				</tr>
				<tr>
					<td class="title3" width="15%">是否有效：</td>
					<td class="title3" width="">
						<input name="activity" type="radio" checked="checked" hidefocus="true" value="1"/>是&nbsp;&nbsp;
						<input name="activity" type="radio" hidefocus="true" value="0"/>否
					</td>
					<td class="title3" width="15%">是否添加操作：</td>
					<td class="title3" width="">
						<input name="action1" type="radio" value="1" onclick="showHidden('tAction')" checked="checked"/>是&nbsp;&nbsp;
						<input name="action1" type="radio" value="0" onclick="showHidden('tAction')"/>否
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr id="tAction" style="display: block;">
		<td valign="top"><br>
			<table class="table_input1" cellpadding="0" cellspacing="0" style="padding: 0 0 0 5px;">
				<!-- 
				<tr>
					<td class="title" width="15%">已有操作：</td>
					<td colspan="3" class="title">
					<c:forEach var="actionp" items="${actions}">${actionp.actionName}</c:forEach>、
					</td>
				</tr>
				 -->
				<tr>
					<td width="15%">操作编码：</td>
					<td><input id="actionCode" name="actionCode" class="input1" type="text"/></td>
					<td width="18%">操作名称：</td>
					<td><input id="actionName" name="actionName" class="input1" type="text"/></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
</body>
</html>